package com.company.thread;

/**
 * @description: some desc
 * @author: ruoan
 * @date: 2020/12/8 13:13
 */
public class SingletonDemo2 {
    private static SingletonDemo2 instance;

    private SingletonDemo2() {
        System.out.println(Thread.currentThread().getName()+"在构造器");
    }

    public static SingletonDemo2 getInstance(){
        if (instance == null) {
            instance = new SingletonDemo2();
        }
        return instance;
    }


    public static void main(String[] args) {

        SingletonDemo2 singletonDemoInMain = SingletonDemo2.getInstance();
        // 创建新线程
        new Thread(() -> {
            SingletonDemo2 singletonDemo = SingletonDemo2.getInstance();
            System.out.println(singletonDemoInMain==singletonDemo);
        },"t1").start();




    }
}
